package registry

import (
	"context"
	"io"
)

type Registry interface {
	// 实例注册
	Register(ctx context.Context, si *ServiceInstance) error
	// 实例注销
	UnRegister(ctx context.Context, si *ServiceInstance) error
	// 获取指定服务下的所有实例
	ListServices(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
	// 订阅实例变更事件
	Subscribe(serviceName string) (<-chan Event, error)
	io.Closer
}

// type ServiceInstance struct {
// 	Name    string
// 	Address string
// 	Weight  uint32
// 	Group   string
// }

type ServiceInstance struct {
	// Region is region.
	Region string `json:"region"`
	// Zone is IDC.
	Zone string `json:"zone"`
	// Env prod/pre、uat/fat1
	Env string `json:"env"`
	// AppID is mapping servicetree appid.
	AppID string `json:"appid"`
	// Hostname is hostname from docker.
	Hostname string `json:"hostname"`
	// Addrs is the address of app instance
	// format: scheme://host
	Addrs []string `json:"addrs"`
	// Version is publishing version.
	Version string `json:"version"`
	// LastTs is instance latest updated timestamp
	LastTs int64 `json:"latest_timestamp"`
	// Metadata is the information associated with Addr, which may be used
	// to make load balancing decision.
	Metadata map[string]string `json:"metadata"`
}

type Event struct {
	// 更新事件类型：ADD UPDATE DELETE
	Type string
}
